package com.sh.哈希;

import java.util.HashSet;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 最长连续序列 {
    public static void main(String[] args) {
        int[] nums = new int[]{100, 4, 200, 1, 3, 2};

    }
    public static int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int res = 0;
        for (Integer i : set) {
            int temp = i;
            int tempRes = 0;
            while (set.contains(temp+1)){
                temp++;
                tempRes++;
            }
            res = Math.max(res,tempRes+1);
        }

        return res;


    }
}

